package com.hjm.project.elementsInfo.elementsInfo.controller;

import java.util.List;

import com.hjm.common.utils.StringUtils;
import com.hjm.common.utils.Utils;
import com.yxhd.encrypt.EncryptUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.elementsInfo.elementsInfo.domain.ElementsInfo;
import com.hjm.project.elementsInfo.elementsInfo.service.IElementsInfoService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 要素认证行为记录Controller
 * 
 * @author LOVE
 * @date 2020-11-28
 */
@Controller
@RequestMapping("/elementsInfo/elementsInfo")
public class ElementsInfoController extends BaseController
{
    private String prefix = "elementsInfo/elementsInfo";

    @Autowired
    private IElementsInfoService elementsInfoService;

    @RequiresPermissions("elementsInfo:elementsInfo:view")
    @GetMapping()
    public String elementsInfo()
    {
        return prefix + "/elementsInfo";
    }

    /**
     * 查询要素认证行为记录列表
     */
    @RequiresPermissions("elementsInfo:elementsInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ElementsInfo elementsInfo)throws Exception
    {
        startPage();
        List<ElementsInfo> list = elementsInfoService.selectElementsInfoList(elementsInfo);
        for(int i=0;i<list.size();i++){
            if (StringUtils.isNotEmpty(list.get(i).getScreenNumDense())) {
                list.get(i).setScreenNumDense(Utils.dealCard(EncryptUtils.getDecrypt(list.get(i).getScreenNumDense())));
            }
            if (StringUtils.isNotEmpty(list.get(i).getIdnumberDense())) {
                list.get(i).setIdnumberDense(Utils.dealCard(EncryptUtils.getDecrypt(list.get(i).getIdnumberDense())));
            }
            if (StringUtils.isNotEmpty(list.get(i).getResphone())) {
                list.get(i).setResphone(Utils.dealPhone(list.get(i).getResphone()));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出要素认证行为记录列表
     */
    @RequiresPermissions("elementsInfo:elementsInfo:export")
    @Log(title = "要素认证行为记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ElementsInfo elementsInfo)
    {
        List<ElementsInfo> list = elementsInfoService.selectElementsInfoList(elementsInfo);
        ExcelUtil<ElementsInfo> util = new ExcelUtil<ElementsInfo>(ElementsInfo.class);
        return util.exportExcel(list, "elementsInfo");
    }

    /**
     * 新增要素认证行为记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存要素认证行为记录
     */
    @RequiresPermissions("elementsInfo:elementsInfo:add")
    @Log(title = "要素认证行为记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ElementsInfo elementsInfo)
    {
        return toAjax(elementsInfoService.insertElementsInfo(elementsInfo));
    }

    /**
     * 修改要素认证行为记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ElementsInfo elementsInfo = elementsInfoService.selectElementsInfoById(id);
        mmap.put("elementsInfo", elementsInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存要素认证行为记录
     */
    @RequiresPermissions("elementsInfo:elementsInfo:edit")
    @Log(title = "要素认证行为记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ElementsInfo elementsInfo)
    {
        return toAjax(elementsInfoService.updateElementsInfo(elementsInfo));
    }

    /**
     * 删除要素认证行为记录
     */
    @RequiresPermissions("elementsInfo:elementsInfo:remove")
    @Log(title = "要素认证行为记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(elementsInfoService.deleteElementsInfoByIds(ids));
    }
}
